package com.planet.portal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.planet.common.annotation.Log;
import com.planet.common.core.controller.BaseController;
import com.planet.common.core.domain.AjaxResult;
import com.planet.common.enums.BusinessType;
import com.planet.portal.domain.PortalDish;
import com.planet.portal.service.IPortalDishService;
import com.planet.common.utils.poi.ExcelUtil;
import com.planet.common.core.page.TableDataInfo;

/**
 * 门户网站菜品Controller
 * 
 * @author ggm
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/portal/dish")
public class PortalDishController extends BaseController
{
    @Autowired
    private IPortalDishService portalDishService;

    /**
     * 查询门户网站菜品列表
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:list')")
    @GetMapping("/list")
    public TableDataInfo list(PortalDish portalDish)
    {
        startPage();
        List<PortalDish> list = portalDishService.selectPortalDishList(portalDish);
        return getDataTable(list);
    }

    /**
     * 导出门户网站菜品列表
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:export')")
    @Log(title = "门户网站菜品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PortalDish portalDish)
    {
        List<PortalDish> list = portalDishService.selectPortalDishList(portalDish);
        ExcelUtil<PortalDish> util = new ExcelUtil<PortalDish>(PortalDish.class);
        util.exportExcel(response, list, "门户网站菜品数据");
    }

    /**
     * 获取门户网站菜品详细信息
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:query')")
    @GetMapping(value = "/{dishId}")
    public AjaxResult getInfo(@PathVariable("dishId") Long dishId)
    {
        return success(portalDishService.selectPortalDishByDishId(dishId));
    }

    /**
     * 新增门户网站菜品
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:add')")
    @Log(title = "门户网站菜品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PortalDish portalDish)
    {
        return toAjax(portalDishService.insertPortalDish(portalDish));
    }

    /**
     * 修改门户网站菜品
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:edit')")
    @Log(title = "门户网站菜品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PortalDish portalDish)
    {
        return toAjax(portalDishService.updatePortalDish(portalDish));
    }

    /**
     * 删除门户网站菜品
     */
    @PreAuthorize("@ss.hasPermi('portal:dish:remove')")
    @Log(title = "门户网站菜品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishIds}")
    public AjaxResult remove(@PathVariable Long[] dishIds)
    {
        return toAjax(portalDishService.deletePortalDishByDishIds(dishIds));
    }
}
